// import Cookies from 'js-cookie'
import { ping } from '@/api/key';

const state = {
  ping: false,
  host:"",
  port:"",
  pass:""
}

const mutations = {
  SET_PING: (state, ping1) => {
    state.ping = ping1
  },
  SET_REDIS: (state, data) => {
    state.host = data.host
    state.port = data.port
    state.pass = data.pass
  },
}

const actions = {
  setPing({ commit }, ping1) {
    commit('SET_PING', ping1)
  },
  ping({ commit }) {
    return new Promise((resolve, reject) => {
      ping().then((res) => {
        commit('SET_PING', true)
        commit('SET_REDIS', {
          host:res.data.map.host,
          port:res.data.map.port,
          pass:res.data.map.pass,
        })
        resolve(res)
        
      }).catch((res) => {
        commit('SET_PING', false)
        reject(res)
      })
    })
  },

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
